package _spring_test._MessageSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * @Author: huangya
 * @Date: 2021/01/19
 * @Description:
 */
public class ResourceBundleMessageSourceTest {

    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("_MessageSource\\application-message-source.xml");
        //①获取MessageSource的Bean
        MessageSource messageSource = ac.getBean("messageSource", MessageSource.class);

        Object[] params = {"John", new GregorianCalendar().getTime()};

        //②获取格式化的国际化信息
        String str1 = messageSource.getMessage("greeting.common", params, Locale.US);
        String str2 = messageSource.getMessage("greeting.morning", params, Locale.CHINA);
        String str3 = messageSource.getMessage("greeting.afternoon", params, Locale.CHINA);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
